﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
namespace QuanLyThuoc.DAL
{
   public class PhieuNhapDAL:KetNoiDAL
    {
       public DataTable SelectAll_PhieuNhap()
       {
           SqlCommand cmd = new SqlCommand("SelectAll_PhieuNhap", Connect());
           cmd.CommandType = CommandType.StoredProcedure;
           SqlDataAdapter da = new SqlDataAdapter(cmd);
           DataTable dt = new DataTable();
           da.Fill(dt);
           return dt;
       }
       public DataTable SelectTamMax_PhieuNhap()
       {
           SqlCommand cmd = new SqlCommand("SelectTamNMax", Connect());
           cmd.CommandType = CommandType.StoredProcedure;
           SqlDataAdapter da = new SqlDataAdapter(cmd);
           DataTable dt = new DataTable();
           da.Fill(dt);
           return dt;
       }
       public DataTable SelectIDPhieuNhap(string IdPhieuNhap)
       {
           SqlCommand cmd = new SqlCommand("SelectID_PhieuNhap", Connect());
           cmd.CommandType = CommandType.StoredProcedure;
           cmd.Parameters.AddWithValue("@IDPN", IdPhieuNhap);
           SqlDataAdapter da = new SqlDataAdapter(cmd);
           DataTable dt = new DataTable();
           da.Fill(dt);
           return dt;
       }
       public int InsertPhieuNhap(string IDPN,DateTime NgayNhap, int IdNhaCC, string GhiChu)
       {
           
               SqlCommand cmd = new SqlCommand("Insert_PhieuNhap", Connect());
               cmd.CommandType = CommandType.StoredProcedure;
               cmd.Parameters.AddWithValue("@IDPN", IDPN);
               cmd.Parameters.AddWithValue("@NgayNhap", NgayNhap);
               cmd.Parameters.AddWithValue("@IDNCC", IdNhaCC);
               cmd.Parameters.AddWithValue("@GhiChu", GhiChu);
            return   cmd.ExecuteNonQuery();
          
       }
       public int UpdatePhieuNhap(string IDPN, DateTime NgayNhap, int IdNhaCC, string GhiChu)
       {
           
               SqlCommand cmd = new SqlCommand("Update_PhieuNhap", Connect());
               cmd.CommandType = CommandType.StoredProcedure;
               cmd.Parameters.AddWithValue("@IDPN", IDPN);
               cmd.Parameters.AddWithValue("@NgayNhap", NgayNhap);
               cmd.Parameters.AddWithValue("@IDNCC", IdNhaCC);
               cmd.Parameters.AddWithValue("@GhiChu", GhiChu);
             return  cmd.ExecuteNonQuery();
          
       }
       public int DeletePhieuNhap(string IDPN)
       {
               SqlCommand cmd = new SqlCommand("Delete_PhieuNhap", Connect());
               cmd.CommandType = CommandType.StoredProcedure;
               cmd.Parameters.AddWithValue("@IDPN", IDPN);
              return cmd.ExecuteNonQuery();
           
       }
    }
}
